<template>
	<div class="app-container">
    <div class="filter-container c-flex-row c-aligni-center c-justify-sb">
      <el-form class="form-container">
          <el-input @keyup.enter.native="handleFilter" v-model="listQuery.phoneNum" clearable placeholder="请输入手机号搜索" class="width150"></el-input>
          <el-select clearable class="width120" v-model="listQuery.isCash" placeholder="状态">
            <el-option
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <el-select clearable class="width120" v-model="listQuery.cashType" placeholder="提现方式">
            <el-option
              v-for="item in methodsOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
          <el-date-picker type="date" :editable="false" @change="timeCheck(1)" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="申请时间（开始）" v-model="listQuery.apply_time" style="width:165px;">
          </el-date-picker><span class="c-ph10 font-s12 c-fc-xgray">到</span>
          <el-date-picker type="date" :editable="false" @change="timeCheck(2)" format="yyyy-MM-dd" value-format="yyyy-MM-dd" placeholder="申请时间（结束）"  v-model="listQuery.end_time" style="width:165px;">
          </el-date-picker>
          <el-button type="primary" icon="el-icon-search" @click="handleFilter" class="search">搜索</el-button>

        <el-button class="margin-t10" @click="handleDownload">导出Excel</el-button>
      </el-form>
		</div>
		<div>
			<el-table :data="tableData" :header-row-style="{'font-family': 'PingFangSC-Semibold','backgroundColor': '#f5f7fa','color':'#5c6065'}" row-key="id" v-loading="listLoading" element-loading-text="加载中..." fit highlight-current-row class="table c-width100 color-222 family-PingFangSC-Regular font-s12">
			 	<el-table-column align="center" label="提现方式">
			        <template slot-scope="scope">
			          <span v-if="scope.row.dest == 1">银行卡</span>
                <span v-if="scope.row.dest == 2">微信</span>
			        </template>
		      	</el-table-column>
            <el-table-column align="center" label="用户">
							<template slot-scope="scope">
                <img :src="scope.row.headimgurl != null && scope.row.headimgurl != '' ? scope.row.headimgurl : require('../../../assets/default_head.png')" style="width:40px;height:40px;border-radius:100%;vertical-align:middle;">
			          <br><span>{{scope.row.nickname}}</span>
			        </template>
		      	</el-table-column>
		      	<el-table-column align="center" width="100" label="手机号">
			        <template slot-scope="scope">
			          <span>{{scope.row.mobile}}</span>
			        </template>
			    </el-table-column>
          <el-table-column width="230" align="center" label="银行">
            <template slot-scope="scope">
              <span v-if="scope.row.dest == 1">
                <div class="c-width100 c-textAlign-l">
                  <span><b>银行：</b>{{scope.row.bankName}}</span><br>
                  <span><b>卡号：</b>{{scope.row.bankNo}}</span><br>
                  <span><b>开户名：</b>{{scope.row.holder}}</span><br>
                  <!-- <span><b>电话：</b>{{scope.row.preservedMobile}}</span><br> -->
                  <span><b>支行名称：</b>{{scope.row.branch}}</span>
                </div>

              </span>
            </template>
			    </el-table-column>
          <el-table-column align="center" label="提现金额">
            <template slot-scope="scope">
              <span>{{scope.row.amount}}</span>
            </template>
			    </el-table-column>
          <el-table-column align="center" label="手续费">
            <template slot-scope="scope">
              <span>{{scope.row.fee}}</span>
            </template>
			    </el-table-column>
          <el-table-column align="center" label="申请时间">
            <template slot-scope="scope">
              <span>{{scope.row.createdAt}}</span>
            </template>
			    </el-table-column>
			    <el-table-column align="center" label="审核时间">
            <template slot-scope="scope">
              <span>{{scope.row.updatedAt}}</span>
            </template>
			    </el-table-column>
			    <el-table-column align="center" label="状态">
			        <template slot-scope="scope">
			          <span v-if="scope.row.status == 1">审核中</span>
                <span v-if="scope.row.status == 2" style="color: deepskyblue;">提现成功</span>
                <span v-if="scope.row.status == 3" style="color: green;">提现中</span>
                <span v-if="scope.row.status == -1" style="color: red;">不予提现</span>
                <span v-if="scope.row.status == -2" style="color: red;">提现失败</span>
			        </template>
			    </el-table-column>
			    <el-table-column align="center" width="100" label="操作" v-if="permission == 3">
			        <template slot-scope="scope">
			        	<div v-if="scope.row.status=='未打款'">
			        		<b @click="setPaid">设置已付</b>
			        		<b @click="backApply">回退申请</b>
			        	</div>
                <div v-if="scope.row.status == 1 || scope.row.status == -2">
                  <b @click="qualified(scope.row.wId, scope.row.userId, 2, scope.$index, scope.row.dest)">审核通过</b>
                  <div><b @click="qualified(scope.row.wId, scope.row.userId, -1, scope.$index, scope.row.dest)">不通过</b></div>
                </div>
              </template>
			    </el-table-column>
		   </el-table>
		   <div class="block text-c">
				<!--分页组件 current-page:当前页   -->
				<!--   page-sizes:每页几条数据（选项）   -->
				<!--   page-size:每页几条数据   -->
				<!--   total:总条数   -->
			    <el-pagination
			      @size-change="handleSizeChange"
			      @current-change="handleCurrentChange"
			      :current-page="listQuery.page"
			      :page-sizes="[10, 20, 30, 50]"
			      :page-size="10"
			      layout="total, sizes, prev, pager, next, jumper"
			      :total="listQuery.total">
			    </el-pagination>
			</div>
		</div>
	</div>
</template>
<script>
import { getWithdrawList, withdrawApply } from '@/api/finance'
import { financed_cashManage } from '@/utils/permission'
export default {
  data() {
    return {
      permission: 3,
      currentPage: 1, // 当前页
      total: null, // 数据总条数
      listQuery: {
        total: null,
        apply_time: null,
        end_time: null,
        phoneNum: null,
        isCash: null,
        cashType: null
      },
      listLoading: false,
      companyId: null,
      URLAPI: process.env.BASE_API,
      tableData: [],
      statusOptions: [{
        value: '1',
        label: '审核中'
      }, {
        value: '2',
        label: '提现成功'
      }, {
        value: '3',
        label: '提现中'
      }, {
        value: '-1',
        label: '不予提现'
      }, {
        value: '-2',
        label: '提现失败'
      }],
      methodsOptions: [
        {
          value: '1',
          label: '银行卡'
        }, {
          value: '2',
          label: '微信'
        }]
    }
  },
  created() {
    this.getModelPermission()
    this.getList()
  },
  methods: {
    getModelPermission() {
      this.permission = financed_cashManage()
    },
    handleDownload() {
      var form = ''
      if (this.listQuery.apply_time) {
        form += '&apply_time=' + this.listQuery.apply_time
      }
      if (this.listQuery.end_time) {
        form += '&end_time=' + this.listQuery.end_time
      }
      if (this.listQuery.phoneNum) {
        form += '&phoneNum=' + this.listQuery.phoneNum
      }
      if (this.listQuery.isCash) {
        form += '&isCash=' + this.listQuery.isCash
      }
      if (this.listQuery.cashType) {
        form += '&cashType=' + this.listQuery.cashType
      }
      window.open(this.URLAPI + '/excel/excelWithdrawLists?companyId=' + this.companyId + form)
    },
    getList() {
      this.listLoading = true
      getWithdrawList(this.listQuery).then(res => {
        this.tableData = res.data.data.list.data
        this.listQuery.total = res.data.data.list.total
        this.companyId = res.data.data.companyId
        this.listLoading = false
      }).catch(err => {
        console.log(err)
      })
    },
    qualified(wId, userId, status, index, dest) {
      this.$confirm('确定审核' + (status == 2 ? '' : '不') + '通过？' + ((status == 2 && dest == 1) ? '该提现为银行卡提现，确定后请线下汇款！' : ''), '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var data = { wId: wId, userId: userId, status: status }
        this.listLoading = true
        withdrawApply(data).then(res => {
          this.listLoading = false
          if (res.data.statusCode == 200) {
            this.$message({
              type: 'success',
              message: '操作成功'
            })
            this.tableData[index].status = res.data.data
          }
          if (res.data.statusCode == 500) {
            this.$message({
              type: 'error',
              message: '操作失败'
            })
          }
        }).catch(err => {
          this.listLoading = false
          console.log(err)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消'
        })
      })
    },
    handleSizeChange(val) { // 切换每页几条数据方法
      // console.log(`每页 ${val} 条`)
      this.listQuery.limit = val
      this.getList()
    },
    handleCurrentChange(val) { // 切换当前页
      // console.log(`当前页: ${val}`)
      this.listQuery.page = val
      this.getList()
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
    timeCheck(type) {
      if (this.listQuery.apply_time && this.listQuery.end_time && this.listQuery.apply_time > this.listQuery.end_time) {
        this.$message({
          message: '结束时间不能小于开始时间',
          type: 'error'
        })

        if (type == 1) {
          this.listQuery.apply_time = null
        } else {
          this.listQuery.end_time = null
        }
      }
    }
  }
}
</script>

<style scoped>
</style>
